#ifndef AUTOAIM_DETECTOR__DETECTOR_HPP_
#define AUTOAIM_DETECTOR__DETECTOR_HPP_

#include <string>
#include <vector>

#include <opencv2/opencv.hpp>

#include "descriptor.hpp"
#include "number_classifier.hpp"

namespace detector {

class Detector {
 public:
  using Ptr = std::unique_ptr<Detector>;

  struct LightParams {
    // width / height
    double min_ratio;
    double max_ratio;
    // vertical angle
    double max_angle;
  };
  struct ArmorParams {
    double min_light_ratio;
    double min_small_center_distance;
    double max_small_center_distance;
    double min_large_center_distance;
    double max_large_center_distance;
    // horizontal angle
    double max_angle;
  };

  Detector(const int &light_thresh, const LightParams &light_params,
           const ArmorParams &armor_params, const std::string &model_path);

  cv::Mat preprocessImage(const cv::Mat &src, const int &color);

  std::vector<Light> findLights(const cv::Mat &rgb_img,
                                const cv::Mat &binary_img);

  std::vector<Armor> matchLights(const std::vector<Light> &lights,
                                 const int &color);

  std::vector<Armor> numberClassify(std::vector<Armor> &armors,
                                    cv::Mat &rgb_img);

  void set_lightness_thresh(const int &lightness_thresh);

 private:
  bool isLight(const Light &light);

  bool containLight(const Light &light_1, const Light &light_2,
                    const std::vector<Light> &lights);

  bool isArmor(Armor &armor);

 private:
  int min_lightness_;
  LightParams l_;
  ArmorParams a_;
  NumberClassifier::Ptr classifier_;
};

}  // namespace detector
#endif  // AUTOAIM_DETECTOR__DETECTOR_HPP_